package com.agricultural.robot.command;

import java.util.Stack;

/**
 * 命令调用者 - 命令模式
 */
public class CommandInvoker {
    private Stack<Command> commandHistory;

    public CommandInvoker() {
        commandHistory = new Stack<>();
    }

    public void executeCommand(Command command) {
        command.execute();
        commandHistory.push(command);
    }

    public void undoLastCommand() {
        if (!commandHistory.isEmpty()) {
            Command command = commandHistory.pop();
            command.undo();
        } else {
            System.out.println("没有可撤销的命令");
        }
    }
}
